package assemblers.beans;

import assemblers.interfaces.PhoneNumberInfoAssembler;
import infos.PhoneNumberInfo;
import model.PhoneNumber;

import javax.ejb.Stateless;
import java.util.ArrayList;
import java.util.List;

@Stateless(name = "PhoneNumberInfoAssembler")
public class PhoneNumberInfoAssemblerBean implements PhoneNumberInfoAssembler {

    @Override
    public PhoneNumberInfo assemble(PhoneNumber phoneNumber) {
        PhoneNumberInfo phoneNumberInfo = new PhoneNumberInfo();
        phoneNumberInfo.setId(phoneNumber.getId());
        phoneNumberInfo.setCode(phoneNumber.getCode());
        phoneNumberInfo.setNumber(phoneNumber.getNumber());
        phoneNumberInfo.setPersonId(phoneNumber.getPerson().getId());
        return phoneNumberInfo;
    }

    @Override
    public List<PhoneNumberInfo> assembleList(List<PhoneNumber> phoneNumbers) {
        List<PhoneNumberInfo> phoneNumberInfos = new ArrayList<PhoneNumberInfo>();
        for (PhoneNumber phoneNumber : phoneNumbers) {
            PhoneNumberInfo phoneNumberInfo = assemble(phoneNumber);
            phoneNumberInfos.add(phoneNumberInfo);
        }
        return phoneNumberInfos;
    }
}
